package com.marchsoft.musicalstore.controller;
import com.marchsoft.musicalstore.entity.OrderMy;
import com.marchsoft.musicalstore.entity.Orders;
import com.marchsoft.musicalstore.service.OrderSer;
import com.marchsoft.musicalstore.util.RequestToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orderCon")
public class OrderCon {
    @Autowired
    OrderSer orderSer;

    /**
     * 按需查询订单
     * @param id 用户id
     * @param isOut 订单状态
     * @return
     */
    @RequestMapping(path = "/getOrder",method = RequestMethod.GET)
    public RequestToJson getAllOrder(Integer id, Integer isOut){
        List<Map<String, Object>> orderMyList =  orderSer.showShopCart(id,isOut);
        RequestToJson requestToJson = new RequestToJson(0,"成功",orderMyList);
        return requestToJson;
    }

    /**
     * 购物车增加或减少商品数量
     * @param id 订单id
     * @return
     */
    @RequestMapping(path = "/changeOrder",method = RequestMethod.POST)
    public RequestToJson changeCart(Integer id,Integer isAdd){
        OrderMy order = orderSer.getProductNum(id,isAdd);
        RequestToJson requestToJson = new RequestToJson(0,"成功",order);
        return requestToJson;
    }
}
